/* Copyright (c) 2010, David Kreuter. See LICENSE for more information */

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Spinner.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Value_Input.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_File_Chooser.H>
#include <math.h>
#include <list>

extern "C"{
#include "headers.h"
}

using namespace std;

narc *n;
static int apilock=0;

void from_form(){
}

void to_form(){
}

void load_build_model(Fl_Widget*, void*){
	Fl_File_Chooser chooser(".","*.narc",Fl_File_Chooser::SINGLE,
		"Select your build_model.narc");

	chooser.show();
	while(chooser.shown())Fl::wait();
	if(chooser.value()==NULL)return;

	if(n)free_narc(n);
	uint8 *buf; uint32 len;
	read_file((char*)chooser.value(),&buf,&len);
	n=read_narc(buf,len);
	free(buf);
}

// The names don't have any meaning. They only exist to be short

#define NG(u,v,w) {v* o=new v w; u=o;
#define UG(v,w) {v* o=new v w;
#define BYTE o->minimum(0); o->maximum(255); o->value(0);
#define EG o->align(FL_ALIGN_TOP); }
#define HG o->end(); }
#define FG }

Fl_Double_Window *win;
Fl_Choice *poke_chooser;
Fl_Input *poke_name, *weight_str, *height_str;
Fl_Group *if_rom_group;
Fl_Spinner *base_hp , *eff_hp ;
Fl_Spinner *base_atk, *eff_atk;
Fl_Spinner *base_def, *eff_def;
Fl_Spinner *base_spd, *eff_spd;
Fl_Spinner *base_sak, *eff_sak;
Fl_Spinner *base_sdf, *eff_sdf;
Fl_Spinner *female_rate, *catch_rate, *run_rate;

void make_gui(){
	NG(win,Fl_Double_Window,(600, 280, "Pokemon Editor"))
	UG(Fl_Button,(300,  0, 100, 20, "Read File(s)")) FG
	NG(if_rom_group,Fl_Group,(0, 0, 600, 280)) o->deactivate();
	UG(Fl_Button,(300, 20, 100, 20, "Write File(s)")) FG

	NG(poke_chooser,Fl_Choice,(0, 20, 150, 20, "Pokemon")) EG
	NG(poke_name,Fl_Input,(150, 20, 150, 20, "Name")) EG

	NG(weight_str,Fl_Input,(  0, 180, 100, 20, "Weight")) EG
	NG(height_str,Fl_Input,(200, 180, 100, 20, "Height")) EG

	NG(base_hp ,Fl_Spinner,(  0, 60, 50, 20, "HP"   )) BYTE EG
	NG(base_atk,Fl_Spinner,( 50, 60, 50, 20, "Atk"  )) BYTE EG
	NG(base_def,Fl_Spinner,(100, 60, 50, 20, "Def"  )) BYTE EG
	NG(base_spd,Fl_Spinner,(150, 60, 50, 20, "Spd"  )) BYTE EG
	NG(base_sak,Fl_Spinner,(200, 60, 50, 20, "SpAtk")) BYTE EG
	NG(base_sdf,Fl_Spinner,(250, 60, 50, 20, "SpDef")) BYTE EG

	NG( eff_hp ,Fl_Spinner,(300, 60, 50, 20, "HP"   )) BYTE EG
	NG( eff_atk,Fl_Spinner,(350, 60, 50, 20, "Atk"  )) BYTE EG
	NG( eff_def,Fl_Spinner,(400, 60, 50, 20, "Def"  )) BYTE EG
	NG( eff_spd,Fl_Spinner,(450, 60, 50, 20, "Spd"  )) BYTE EG
	NG( eff_sak,Fl_Spinner,(500, 60, 50, 20, "SpAtk")) BYTE EG
	NG( eff_sdf,Fl_Spinner,(550, 60, 50, 20, "SpDef")) BYTE EG

	NG(female_rate,Fl_Spinner,(0, 100, 100, 20, "Female rate")) BYTE EG
	NG( catch_rate,Fl_Spinner,(100, 100, 100, 20, "Catch rate")) BYTE EG
	NG(   run_rate,Fl_Spinner,(200, 100, 100, 20, "Run rate")) BYTE EG
    { Fl_Choice* o = new Fl_Choice(400, 180, 100, 20, "Type 1");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(500, 180, 100, 20, "Type 2");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Spinner* o = new Fl_Spinner(300, 100, 100, 20, "Hatch Multi.");
      o->minimum(0);
      o->maximum(255);
      o->value(0);
      o->align(FL_ALIGN_TOP);
    } // Fl_Spinner* o
    { Fl_Spinner* o = new Fl_Spinner(400, 100, 100, 20, "EXP Base");
      o->minimum(0);
      o->maximum(255);
      o->value(0);
      o->align(FL_ALIGN_TOP);
    } // Fl_Spinner* o
    { Fl_Spinner* o = new Fl_Spinner(500, 100, 100, 20, "Happy Base");
      o->minimum(0);
      o->maximum(255);
      o->value(0);
      o->align(FL_ALIGN_TOP);
    } // Fl_Spinner* o
    { Fl_Choice* o = new Fl_Choice(200, 140, 100, 20, "Item 1");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(300, 140, 100, 20, "Item 2");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(0, 140, 100, 20, "Ability 1");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(100, 140, 100, 20, "Ability 2");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(400, 140, 100, 20, "Egg group 1");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Choice* o = new Fl_Choice(500, 140, 100, 20, "Egg group 1");
      o->down_box(FL_BORDER_BOX);
      o->align(FL_ALIGN_TOP);
    } // Fl_Choice* o
    { Fl_Value_Input* o = new Fl_Value_Input(100, 180, 100, 20, "DEX-Weight");
      o->maximum(65535);
      o->step(1);
      o->align(FL_ALIGN_TOP);
    } // Fl_Value_Input* o
    { Fl_Value_Input* o = new Fl_Value_Input(300, 180, 100, 20, "DEX-Height");
      o->maximum(65535);
      o->step(1);
      o->align(FL_ALIGN_TOP);
    } // Fl_Value_Input* o

	UG(Fl_Button,(400,  0, 100, 20, "Save Poke")) FG
	UG(Fl_Button,(400, 20, 100, 20, "Evolution")) FG
	UG(Fl_Button,(500,  0, 100, 20, "TM/HM")) FG
	UG(Fl_Button,(500, 20, 100, 20, "Moves")) FG

	NG(exp_max   ,Fl_Choice,(400, 220, 100, 20, "EXP Max"  )) EG
	NG(body_stlye,Fl_Choice,(500, 220, 100, 20, "Bodystyle")) EG

	NG(desc1,Fl_Choice,(0, 220, 200, 20, "Short description")) EG
	NG(desc2,Fl_Choice,(200, 220, 200, 20, "Long description")) EG
	HG
    o->size_range(600, 280, 600, 280);
	HG
}

int main() {
	n=(narc*)0;
	make_gui();
	win->show();
	return(Fl::run());
}
